package cn.wolfcode.trip.admin.controller;

import cn.wolfcode.trip.base.domain.StrategyCatalog;
import cn.wolfcode.trip.base.query.StrategyCatalogQueryObject;
import cn.wolfcode.trip.base.service.IStrategyCatalogService;
import cn.wolfcode.trip.base.service.IStrategyService;
import cn.wolfcode.trip.base.util.JSONResult;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/strategyCatalog")
public class StrategyCatalogController {
    @Autowired
    private IStrategyCatalogService strategyCatalogService;
    @Autowired
    private IStrategyService strategyService;
    @RequestMapping("list")
    public String list(@ModelAttribute("qo") StrategyCatalogQueryObject qo, Model model){
        qo.setOrderBy("sc.sequence");
        PageInfo pageInfo = strategyCatalogService.query(qo);
        model.addAttribute("pageInfo",pageInfo);
        model.addAttribute("strategys",strategyService.selectAll());
        return "/strategyCatalog/list";
    }
    @RequestMapping("saveOrUpdate")
    @ResponseBody
    public JSONResult saveOrUpdate(StrategyCatalog strategyCatalog){
        strategyCatalogService.saveOrUpdate(strategyCatalog);
        return new JSONResult();
    }
    @GetMapping
    @ResponseBody
    public List<StrategyCatalog> getStrategy(Long id){
        return strategyCatalogService.selectByStrategyId(id);
    }
}
